import csv
import datetime
data = [
    ["Name", "Age", "City"],
    ["Alice", 30, "New York"],
    ["Bob", 25, "San Francisco"],
    ["Charlie", 22, "Los Angeles"]
]

# 指定写入的CSV文件名
file_name = f"./py01/PythonApp01/data/{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}output.csv"

# 以写入模式打开CSV文件
with open(file_name, "w", newline="", encoding="utf-8") as csvfile:
    # 创建csv.writer对象
    csv_writer = csv.writer(csvfile)

    # 遍历data列表，逐行写入CSV文件
    for row in data:
        csv_writer.writerow(row)

print(f"数据已成功写入文件：{file_name}")
